package cn.snmp.mutual.org.opennms.protocols.snmp;

import java.io.*;
import java.math.*;

import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnDecodingException;
import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnEncoder;
import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnEncodingException;


public class SnmpCounter64 implements SnmpSyntax, Cloneable, Serializable {
    private BigInteger m_value;
    public static final byte ASNTYPE = 70;

    public SnmpCounter64() {
        (this.m_value = BigInteger.valueOf(0L)).clearBit(65);
    }

    public SnmpCounter64(final long value) {
        (this.m_value = BigInteger.valueOf(value & Long.MAX_VALUE)).clearBit(65);
    }

    public SnmpCounter64(final BigInteger value) {
        (this.m_value = new BigInteger(value.toByteArray())).clearBit(65);
    }

    public SnmpCounter64(final SnmpCounter64 second) {
        (this.m_value = new BigInteger(second.m_value.toByteArray())).clearBit(65);
    }

    public BigInteger getValue() {
        return this.m_value;
    }

    public void setValue(final BigInteger value) {
        (this.m_value = new BigInteger(value.toByteArray())).clearBit(65);
    }

    public byte typeId() {
        return 70;
    }

    public int encodeASN(final byte[] buf, final int offset, final AsnEncoder encoder) throws AsnEncodingException {
        return encoder.buildUInteger64(buf, offset, this.typeId(), this.getValue());
    }

    public int decodeASN(final byte[] buf, final int offset, final AsnEncoder encoder) throws AsnDecodingException {
        final Object[] rVals = encoder.parseUInteger64(buf, offset);
        if ((byte) rVals[1] != this.typeId()) {
            throw new AsnDecodingException("Invalid ASN.1 type");
        }
        this.setValue((BigInteger) rVals[2]);
        return (int) rVals[0];
    }

    public SnmpSyntax duplicate() {
        return new SnmpCounter64(this);
    }

    public Object clone() {
        return new SnmpCounter64(this);
    }

    @Override
    public String toString() {
        return String.valueOf(this.getValue());
    }
}
